﻿<%@ WebHandler Language="C#" Class="list" %>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;
using System.Web.Script.Serialization;
using System.Web.SessionState;
using System.Web.Services;

public class list : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
    private StringBuilder sb = null;
    public DataSet ds = null;
    public DataTable dt = null;
    private string sqlwhere = "";
    public void ProcessRequest (HttpContext context) {
        string type = PageBase.ext_string(context.Request.Params["type"]);
        switch (type)
        {

            //获取密码
            case "getpwd":
                getpwd(context);
                break;
            //修改
            case "edit":
                edit(context);
                break;

            default:
                //getinfo(context);
                break;
        }
    }
    //获取密码
    public void getpwd(HttpContext context)
    {
        bool flag;
        string userid = PageBase.ext_string(context.Request.Params["userid"]);
        string where = @"select  password from [sys_users] where id="+userid+"";
        DataTable dt =  DBHelper.ExecuteDataTable(where);
        sb = new StringBuilder();
        if (dt.Rows.Count > 0)
        {
            flag = true;
        }
        else
        {
            flag = false;
        }
        sb.Append("{\"flag\":\"" + flag + "\",\"password\":\"" + dt.Rows[0]["password"].ToString() + "\"}");
        context.Response.Write(sb.ToString());
        context.Response.ContentType = "text/json";
        context.Response.End();
    }

    //修改
    public void edit(HttpContext context)
    {
        string msg = "";
        string sqlsave = "";
        bool flag;
        string userid = PageBase.ext_string(context.Request.Params["userids"]);
        string newpassword = PageBase.ext_string(context.Request.Params["newpassword"]);
        sqlsave = @"update [sys_users] set  [password]='{0}' where id={1};";
        sqlsave = string.Format(sqlsave, newpassword,  userid);
        int zxcount = DBHelper.ExecuteNonQuery(sqlsave);
        if (zxcount > 0)
        {
            flag = true;
            msg = "修改成功";
        }
        else
        {
            flag = false;
            msg = "修改失败，请联系管理员";
        }
        context.Response.Write("{\"flag\":\"" + flag + "\",\"remsg\":\"" + msg + "\"}");
        context.Response.ContentType = "text/json";
        context.Response.End();
    }
    public bool IsReusable {
        get {
            return false;
        }
    }

}